#include<bits/stdc++.h>
using namespace std;
const int N = 20010,K = 1e4+10;
const int MOD = 998244353;
random_device seed;
mt19937 mt(seed());
vector<tuple<int,int,int>> pos;
int qpow(int x,int p){
    int res = 1;
    while(p){
        if(p & 1){
            res = 1ll*res*x%MOD;
        }
        x = 1ll*x*x%MOD;
        p >>= 1;
    }
    return res;
}
vector<int> operator+(vector<int> va,vector<int> vb){
    vector<int> res(va);
    if(vb.size() > va.size()){
        res.resize(vb.size());
    }
    for(int i = 0;i < vb.size();i++){
        res[i] = (res[i] + vb[i])%MOD;
    }
    return res;
}
int a[N],delta[N];
vector<int> Fcur;
vector<int> bfunc;
int bpos,bval;
void calc(int x){
    int res = 0;
    for(int i = 0;i < Fcur.size();i++){
        res = (res + 1ll*Fcur[i]*a[x - 1 - i]%MOD)%MOD; 
    }
    if((a[x] - res + MOD)%MOD == 0){
        return;
    }else if(Fcur.size()){
        delta[x] = (a[x] - res + MOD)%MOD;
        int at = bpos;
        vector<int> dt(x - at + bfunc.size());
        int att = 1ll*delta[x] * qpow(delta[at],MOD - 2)%MOD;
        dt[x - at - 1] = att;
        for(int j = 0;j < bfunc.size();j++){
            dt[x - at + j] = 1ll*((MOD - att)%MOD)*bfunc[j]%MOD;
        }
        if(-x + Fcur.size() < bval){
            bval = -x + Fcur.size();
            bpos = x;
            bfunc = Fcur;
        }
        Fcur = Fcur + dt;
    }else{
        bval = -x;
        bpos = x;
        bfunc = Fcur;
        delta[x] = a[x];
        Fcur = vector<int>(x,0);
    }
}
int main(){
    int n,k;
    cin>>n>>k;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            int x;
            cin>>x;
            if (x){
                pos.push_back(make_tuple(i,j,x));
            }
        }
    }
    vector<int> vec(n);
    vector<int> vec1(n);
    for(int i = 0;i < n;i++){
        vec[i] = mt()%MOD;
        vec1[i] = mt()%MOD;
    }
    for(int i = 0;i <= n*2;i++){
        for(int j = 0;j < n;j++){
            a[i + 1] = (a[i + 1] + 1ll*vec[j]*vec1[j]%MOD)%MOD;
        }
        vector<int> res(n,0);
        for(tuple<int,int,int> ep : pos){
            int x,y,v;
            tie(x,y,v) = ep;
            res[x] = (res[x] + 1ll*v*vec[y]%MOD)%MOD;
        }
        res.swap(vec);
    }
    for(int i = 1;i <= n*2;i++){
        calc(i);
    }
    reverse(Fcur.begin(),Fcur.end());
    cout<<Fcur.size()<<'\n';
    for(int v: Fcur){
        cout<<(MOD - v)%MOD<<' ';
    }
}